﻿using Utils.Extensions;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UtilsIntegrationTests
{
	[TestClass]
	public class IEnumerableExtensionUT
	{
		[TestMethod]
		public void BasicTest1Best()
		{
			IEnumerable<decimal> test = new List<decimal> {1m, 2m, 3m, 4m, 5m, 6m};

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(21, value);
			Assert.AreEqual(0, startIndex);
			Assert.AreEqual(5, endIndex);
		}

		[TestMethod]
		public void BasicTest2Best()
		{
			IEnumerable<decimal> test = new List<decimal> { 1m, -2m, 3m, 4m, 5m, 6m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(18, value);
			Assert.AreEqual(2, startIndex);
			Assert.AreEqual(5, endIndex);
		}

		[TestMethod]
		public void BasicTest3Best()
		{
			IEnumerable<decimal> test = new List<decimal> { 1m, -2m, 3m, 4m, -10m, 6m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(7, value);
			Assert.AreEqual(2, startIndex);
			Assert.AreEqual(3, endIndex);
		}

		[TestMethod]
		public void BasicTest4Best()
		{
			IEnumerable<decimal> test = new List<decimal> { 1m, -2m, 3m, 4m, -10m, 6m, 2m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(8, value);
			Assert.AreEqual(5, startIndex);
			Assert.AreEqual(6, endIndex);
		}

		[TestMethod]
		public void BasicTest5Best()
		{
			IEnumerable<decimal> test = new List<decimal> { 1m, -2m, 3m, 4m, -10m, 6m, 2m, -1, 2 };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(9, value);
			Assert.AreEqual(5, startIndex);
			Assert.AreEqual(8, endIndex);
		}

		[TestMethod]
		public void AllNegativeTest1Best()
		{
			IEnumerable<decimal> test = new List<decimal> { 0m, -1m, -2m, -3m, -4m, -5m, -6m };
																			   
			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(0, value);
			Assert.AreEqual(0, startIndex);
			Assert.AreEqual(0, endIndex);
		}

		[TestMethod]
		public void AllNegativeTest2Best()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, -7m, -3m, -7m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-1, value);
			Assert.AreEqual(0, startIndex);
			Assert.AreEqual(0, endIndex);
		}

		[TestMethod]
		public void BasicTest1Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, -2m, -3m, -4m, -5m, -6m };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-21, value);
			Assert.AreEqual(0, startIndex);
			Assert.AreEqual(5, endIndex);
		}

		[TestMethod]
		public void BasicTest2Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, 2m, -3m, -4m, -5m, -6m };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-18, value);
			Assert.AreEqual(2, startIndex);
			Assert.AreEqual(5, endIndex);
		}

		[TestMethod]
		public void BasicTest3Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, 2m, -3m, -4m, 10m, -6m };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-7, value);
			Assert.AreEqual(2, startIndex);
			Assert.AreEqual(3, endIndex);
		}

		[TestMethod]
		public void BasicTest4Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, 2m, -3m, -4m, 10m, -6m, -2m };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-8, value);
			Assert.AreEqual(5, startIndex);
			Assert.AreEqual(6, endIndex);
		}

		[TestMethod]
		public void BasicTest5Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, 2m, -3m, -4m, 10m, -6m, -2m, 1, -2 };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-9, value);
			Assert.AreEqual(5, startIndex);
			Assert.AreEqual(8, endIndex);
		}

		[TestMethod]
		public void AllPossitiveTest1Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { 1m, 2m, 3m, 4m, 5m, 6m };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(1, value);
			Assert.AreEqual(0, startIndex);
			Assert.AreEqual(0, endIndex);
		}

		[TestMethod]
		public void DefectTest1Worst()
		{
			IEnumerable<decimal> test = new List<decimal> { 18.2m, -21.8m, -1.8m };

			int startIndex;
			int endIndex;
			decimal value = test.FindWorstSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-23.6m, value);
			Assert.AreEqual(1, startIndex);
			Assert.AreEqual(2, endIndex);
		}

		[TestMethod]
		public void DefectTest1BestA()
		{
			IEnumerable<decimal> test = new List<decimal> { 18.2m, -21.8m, -1.8m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(18.2m, value);
			Assert.AreEqual(0, startIndex);
			Assert.AreEqual(0, endIndex);
		}

		[TestMethod]
		public void DefectTest1BestB()
		{
			IEnumerable<decimal> test = new List<decimal> { -18.2m, 21.8m, 1.8m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(23.6m, value);
			Assert.AreEqual(1, startIndex);
			Assert.AreEqual(2, endIndex);
		}

		[TestMethod]
		public void DefectTest1BestC()
		{
			IEnumerable<decimal> test = new List<decimal> { -1m, 2m, 3m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(5m, value);
			Assert.AreEqual(1, startIndex);
			Assert.AreEqual(2, endIndex);
		}

		[TestMethod]
		public void DefectTest2Best()
		{
			IEnumerable<decimal> test = new List<decimal> { -15m, -23m, -476m, -3m, -292m };

			int startIndex;
			int endIndex;
			decimal value = test.FindBestSubsequence(out startIndex, out endIndex);

			Assert.AreEqual(-3m, value);
			Assert.AreEqual(3, startIndex);
			Assert.AreEqual(3, endIndex);
		}
	}
}
